package com.mooral.web.tag.html;

import java.util.ArrayList;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.struts.Globals;
import org.apache.struts.util.PropertyMessageResources;
import org.apache.struts.util.PropertyMessageResourcesFactory;

import com.mooral.bean.Bean;
import com.mooral.bean.Voucher;
import com.mooral.context.Context;
import com.mooral.context.ContextSession;
import com.mooral.web.util.SlugUtils;


public class VoucherTag extends MooralTag {

	protected String sufix = "";

	
	public String getSufix() {
		return sufix;
	}

	public void setSufix(String sufix) {
		this.sufix = sufix;
	}

	@Override
	public int doEndTag(HttpServletRequest request, Context context)throws JspException {

		return 0;
	}

	@Override
	public int doStartTag(HttpServletRequest request, Context context)throws JspException {

		Bean voucher = (Bean) pageContext.findAttribute("voucher");
		
		StringBuffer sb = new StringBuffer();
		
		sb.append("<div class='voucher'>");
			sb.append("<div class=\"title\">"+ voucher.get(sufix + "title")+"</div>");
			sb.append("<div class=\"img\"><img src=\""+ voucher.get(sufix + "image")+"\"/></div>");
			sb.append("<div class=\"description\">"+ voucher.get(sufix + "description")+"</div>");
			sb.append("<div class=\"footer\">");
				sb.append("<a href='/" + context.getApplicationName() + "/voucher/go/"+voucher.get(sufix + "slug") +"' target='_blank'>Show Details</a>");
				// TODO para ver el error cambiar el link por vouchers
				sb.append("<div class='type'><img src='" + context.getApplicationName() + "/images/eng_" + voucher.get(sufix + "type").toString().toLowerCase() + ".png'/></div>");
			sb.append("</div>");
		sb.append("</div>");
		
		
		write(sb.toString());
		
		return 0;
	}



}
